package com.timi_licai.timi_licai_account.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.timi_licai.timi_licai_account.MyConstants;


/**
 * 数据库的操作类
 */
public class DBHelper extends SQLiteOpenHelper {
    private String createAccountBook =
            "create table " + MyConstants.TABLE_ACCOUNT_BOOK +
                    "(_id integer primary key autoincrement," +
                    "bookname text ," +
                    "bookcount integer default(0)," +
                    "ismark integer default(0) ," +
                    "bg_path integer ," +
                    "createtime text default('null') not null )";

    private String createAccountDetails =
            "create table " + MyConstants.TABLE_ACCOUNT_BOOK_DETAILS +
                    "(_id integer primary key autoincrement," +
                    "bookid integer not null ," +
                    "type_id integer not null," +
                    "io_choose integer not null," +
                    "fee float not null  ," +
                    "description text ," +
                    "photo_path text," +
                    "createtime text default('null') not null )";

    private String createAccountType = "create table " +
            MyConstants.TABLE_CONSUME_TYPE +
            "( _id  integer primary key autoincrement," +
            "typename text not null," +
            "ismark integer default(0) ," +
            "typepath text )";
    private String createEditBudge = "create table " +
            MyConstants.TABLE_EDIT_BUDGE +
            "( _id  integer primary key autoincrement," +
            "edit_money integer )";

    private String insertCountBook = "insert into " + MyConstants.TABLE_ACCOUNT_BOOK
            + "(bookname,ismark) values ('默认账本',1)";
    private String inserCategory = "insert into " + MyConstants.TABLE_CONSUME_TYPE +
            "(typename)values('一般支出')";


    public DBHelper(Context context) {
        super(context, MyConstants.DB_NAME, null, MyConstants.DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(createAccountBook);
        db.execSQL(createAccountDetails);
        db.execSQL(createAccountType);
        db.execSQL(createEditBudge);
        db.execSQL(insertCountBook);
        db.execSQL(inserCategory);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
